import { Component, OnInit } from '@angular/core';
import { NbWindowRef } from '@nebular/theme';
import { DtoResultObj } from '../../Model/DtoRec/DtoResult';

@Component({
  selector: 'ngx-edit-model',
  templateUrl: './edit-model.component.html',
  styleUrls: ['./edit-model.component.scss']
})
export class EditModelComponent implements OnInit {
  
  title: string;
  messageList: any[] = [];
  buttons = []
  inputs = []
  /**
   * 所有列表的值
   */
  ItmeArr=new Array<any>();
  bean = {}
  screenHeight:number=document.documentElement.clientHeight*0.5
  screenWidth:number=document.documentElement.clientWidth*0.8

  itemClass:string="col-md-4"

  constructor(
    public windowRef: NbWindowRef,
  ) {
    console.log(this.windowRef.config.context)
  }

  ngOnInit() {
    console.log(this.inputs)

    for (const key in this.inputs) {
      let element = this.inputs[key];
      element["name"]=key
      //只添加可以编辑的
      if(element.editable==null || element.editable==true)
        this.ItmeArr.push(element);
    }

    //计算宽度
    var thisW=this.screenWidth
    if(this.ItmeArr.length<=3){
      thisW=400*this.ItmeArr.length;
      if(this.ItmeArr.length<2)
        this.itemClass="col-md-12"
    }
    if(this.screenWidth>thisW)this.screenWidth=thisW;

    //计算高度，最多5行,3列数据
    var thisH=0;
    if(this.ItmeArr.length<=3*5){
      var rowNum:number=parseInt((this.ItmeArr.length/3)+"");
      if(this.ItmeArr.length % 3!=0){
        rowNum=rowNum+1;
      }
      thisH=85*rowNum;
    }
    if(thisH<140) thisH=140;
    if(this.screenHeight>thisH)this.screenHeight=thisH;


    console.log(this.ItmeArr)
  }
  ButtonClick(even) {
    even(this.bean)
      .then((x: DtoResultObj<any>) => {
        console.log(x)
        if (x.success) {
          this.windowRef.close();
        }
      })
  }


}
